<?php

namespace Util;

class HttpUtil
{

    public static function get($url, $params = array()): bool|string
    {
        $queryString = http_build_query($params);
        $fullUrl = $url . '?' . $queryString;
        return file_get_contents($fullUrl);
    }

    public static function post($url, $data = array()): bool|string
    {
        $options = array(
            'http' => array(
                'method' => 'POST',
                'header' => 'Content-type: application/x-www-form-urlencoded',
                'content' => http_build_query($data),
            ),
        );
        $context = stream_context_create($options);
        return file_get_contents($url, false, $context);
    }

    public static function postJson($url, $data = array()): bool|string
    {
        $options = array(
            'http' => array(
                'method' => 'POST',
                'header' => 'Content-type: application/json',
                'content' => json_encode($data),
            ),
        );
        $context = stream_context_create($options);
        return file_get_contents($url, false, $context);
    }


}